<template>
  <div id="bar">
    <div class="container">
      <div>
        <ol class="breadcrumb">
          <li><a href="#">App封装</a></li>
          <li><a href="#">苹果免签封装</a></li>
          <li class="active">购买</li>
        </ol>
      </div>
      <el-row>
        <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
          <div class="content">
            <div style="padding-bottom: 80px">
              <el-row :gutter="60">
                <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                  <div class="title1">选择套餐内容</div>
                </el-col>
                <el-col :xs="0" :sm="0" :md="2" :lg="2" :xl="2"></el-col>
                <!-- 套餐 -->
                <el-col :xs="24" :sm="24" :md="10" :lg="10" :xl="10" v-for="(item, index) in mealPrice" :key="index">
                  <div>
                    <div class="input-group" @click="itemSelect(index,item)">
                      <div class="form-control panel1" :id="itemSort===index?'panel1':'panel2'">
                        {{item.desc}}
                      </div>
                      <span class="input-group-btn">
                        <div class="btn btn-default box1" :id="itemSort===index?'box1':'box2'">
                          <div :class="itemSort===index?'price1':'price2'">{{item.price}}<span>元</span></div>
                        </div>
                      </span>
                    </div>
                  </div>
                </el-col>
                <el-col :xs="0" :sm="0" :md="2" :lg="2" :xl="2"></el-col>
              </el-row>
              <el-row>
                <el-col :xs="24" :sm="3" :md="3" :lg="3" :xl="3">
                  <div class="title2">支付方式：</div>
                </el-col>
                <el-col :xs="24" :sm="20" :md="20" :lg="20" :xl="20">
                  <div style="margin-top: 70px; margin-left: 20px">
                    <el-button class="wx_button" :class="{payTypeBorder:selectPayType == 'weixin'}"
                      @click="payTypeSelect(1)"><img src="../../../static/price/QianMinTaoCan_WeChat.png"
                        alt="" />&nbsp;微信</el-button>
                    <el-button class="wx_button" :class="{payTypeBorder:selectPayType=='zfb'}"
                      @click="payTypeSelect(2)"><img src="../../../static/price/QianMinTaoCan_Alipay.png"
                        alt="" />&nbsp;支付宝&nbsp;&nbsp;</el-button>
                  </div>
                </el-col>
              </el-row>
              <el-row>
                <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
                  <div class="count">
                    <div class="price">总支付：<span>{{payPrice}}</span>&nbsp;元</div>
                    <div>
                      <el-button class="pay_button" @click="gotPay()">去支付</el-button>
                    </div>
                  </div>
                </el-col>
              </el-row>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script>
  export default {
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      //这里存放数据
      return {
        mealPrice: [], //月份
        title: '',
        color: 'rgb(255,119,34)',
        price: '',
        payPrice: '', //支付金额
        itemSort: 0, //选中套餐
        originalPrice: '', //原价
        selectPayType: 'weixin', //weixin,zfb
        getPayWay: 1, //1微信 2支付宝
        getCode: '', //类型
        endTime: '',
      };
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods: {
      getPrice() {
        this.$post(this.API.priceList).then((res) => {
          let data = res.data;
          this.mealPrice = data.list
        })
      },
      //选择
      itemSelect(index, item) {
        this.itemSort = index;
        if (this.itemSort == index) {
          this.payPrice = item.price;
          this.getCode = item.code;
        }
      },
      getMoney() {
        var params = new URLSearchParams();
        params.append("code", this.getCode);
        params.append("num", 1);
        this.$post(this.API.payCompute, params).then((res) => {
          let data = res.data;
          this.payPrice = data.money
        })
      },
      //选择支付方式
      payTypeSelect(type) {
        this.selectPayType = type == 1 ? "weixin" : "zfb";
        this.getPayWay = type;
      },
      //提交支付
      gotPay() {
        var params = new URLSearchParams();
        params.append("payIndex", this.getCode);
        params.append("num", 1);
        params.append("paytype", this.getPayWay);
        params.append("appid", this.$route.query.appID);
        this.$post(this.API.Payment, params).then((res) => {
          let data = res.data;
          this.orderID = data.orderid;
          if (this.selectPayType == "zfb") {
            document.querySelector("body").innerHTML = res.data; //查找到当前页面的body，将后台返回的form替换掉body内容
            document.forms[0].submit();
          } else {
            //微信
            this.$router.push({
              path: "/wechat",
              name: "wechat",
              query: {
                orderID: this.orderID,
                num: this.selectNum,
                code: this.getCode,
                // appID:this.appID,
              },
            });
          }
        });
      },
    },

    //生命周期 - 创建完成（可以访问当前this实例）
    created() {
      this.getPrice();
      this.endTime = this.$route.query.endTime;
      this.getCode = this.$route.query.code;
      this.$watch('mealPrice', () => {
        this.mealPrice.filter((item, index) => {
          if (item.title === this.endTime) {
            this.itemSort=index;
          }
        })
      }, {
        immediate: true,
        deep: true
      })
      this.getMoney();
      this.color = this.$route.query.color;
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
  };

</script>
<style scoped>
  /* 支付方式选中 start*/
  div>>>.payTypeBorder {
    border: 2px solid #FF7226 !important;
  }

  .breadcrumb a {
    height: 14px;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
    line-height: 16px;
  }

  /* 支付方式选中 end*/
  #bar {
    width: 100%;
    min-height: 472px;
    background-color: rgb(247, 250, 254);
    overflow: hidden;
  }

  .price .wu {
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
  }

  .price .youhui {
    height: 12px;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #F65D26;
  }

  .item {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;

  }

  .unit {
    font-size: 20px;
    font-family: PingFang-SC-Bold, PingFang-SC;
    font-weight: bold;
    color: #FF4A4A;
    margin-bottom: 2px;
  }

  .unit span {
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #999999;
    margin-right: -4px;
  }

  .discounts {
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
  }

  .sale {
    width: 38px;
    height: 16px;
    background: #FF4A4A;
    border-radius: 0px 2px 0px 2px;
    color: #fff;
    font-size: 12px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    text-align: center;
    line-height: 16px;

  }

  .sale1 {
    width: 38px;
    height: 16px;
    background: transparent;
  }

  .number {
    display: flex;
    flex-flow: row wrap;
  }

  .num_box {
    width: 140px;
    height: 80px;
    border-radius: 2px;
    border: 1px solid #FF7226;
    margin-left: 20px;
    margin-top: 40px;
    display: flex;
    /* justify-content: center;
      align-items: center; */
    text-align: center;
    flex-direction: column;
    cursor: pointer;
  }

  .line {
    width: 140px;
    height: 10px;
    background: #FF7226;
    border-radius: 2px;
    margin-top: 2px;
    margin-left: -1px;
  }

  div>>>.pay_button {
    width: 120px;
    height: 40px;
    background: linear-gradient(90deg, #FF9D68 0%, #FF7226 100%);
    border-radius: 4px;
    font-size: 18px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #FFFFFF;
    line-height: 18px;
    padding: 0px;
    border: none;
  }

  .price {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #5A5E66;
    line-height: 16px;
    margin-bottom: 10px;
    margin-left: 4px;
  }

  .price span {
    font-size: 26px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #F65D26;
    line-height: 20px;
  }

  .count {
    display: flex;
    flex-direction: column;
    margin-left: 30px;
    margin-top: 60px;
    margin-bottom: -40px;
  }

  div>>>.wx_button {
    border: 2px solid #FF7226;
  }

  div>>>.wx_button {
    width: 120px;
    height: 44px;
    background: #FFFFFF;
    border-radius: 4px;
    border: 2px solid #EEEEEE;
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
    line-height: 20px;
  }

  div>>>.wx_button img {
    margin-top: -8px;
    margin-left: -6px;
  }

  div>>>.wx_button span {
    margin-top: -px;
  }

  div>>>.buttonurl {
    background: #03a0ec;
    border-radius: 8px;
    color: #fff;
    width: 114px;
    height: 40px;
    font-size: 16px;
    text-align: center;
  }

  .but {
    margin-left: 120px;
    margin-top: -35px;
  }

  .textOne {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
    line-height: 20px;
  }

  .textOne span {
    font-size: 26px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #f65d26;
    line-height: 20px;
    margin: 0px 5px 0px 0px;
  }

  .textTwo {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #5a5e66;
    line-height: 14px;
    margin: 18px 0px 18px 0px;
  }

  .wxicon {
    margin: -5px 3px 0px 0px;
  }

  .wechat {
    font-size: 20px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
    line-height: 20px;
    margin: -28px 0px 0px 35px;
  }

  #bar {
    width: 100%;
    min-height: 472px;
    background-color: rgb(247, 250, 254);
    overflow: hidden;
  }

  .content {
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
    margin-bottom: 30px;
    background-color: white;
  }

  .breadcrumb {
    background: none;
    margin-top: 20px;
  }

  .title1 {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    padding: 40px 0px 0px 24px;
  }

  .title2 {
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    font-size: 16px;
    margin: 80px 0px 0px 24px;
  }

  .title3 {
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    font-size: 16px;
    padding: 40px 0px 0px 0px;
    margin-left: 10px;
    margin-right: 10px;
  }

  .title4 {
    padding: 60px 0px 0px 30px;
  }

  .title5 {
    padding: 85px 0px 0px 30px;
  }

  .textTwo1 {
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #5a5e66;
    line-height: 14px;
    margin: 18px 0px 18px 0px;
  }

  .wxicon1 {
    margin: -5px 3px 0px 0px;
  }

  .wechat1 {
    font-size: 20px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #000000;
    line-height: 20px;
    margin: -28px 0px 0px 35px;
  }

  .border {
    display: flex;
  }

  #panel1 {
    height: 80px;
    font-size: 16px;
    background: #ff7226;
    border-radius: 8px;
    margin-left: 20px;
    margin-right: 20px;
    margin-top: 20px;
    color: #fff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    border: none;
    cursor: pointer;
  }

  #panel2 {
    height: 80px;
    font-size: 16px;
    background: #fff;
    border-radius: 8px;
    margin-left: 20px;
    margin-right: 20px;
    margin-top: 20px;
    color: #757575;
    border: 1px solid #979797;
    display: flex;
    flex-direction: column;
    justify-content: center;
    cursor: pointer;
  }

  #box1 {
    width: 126px;
    height: 80px;
    background: #ffb38b;
    border-radius: 8px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-top: 20px;
    margin-right: 20px;
    border: none;
    cursor: pointer;
  }

  #box2 {
    width: 126px;
    height: 80px;
    background: #fff;
    border-radius: 8px;
    border: 1px solid #979797;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    margin-top: 20px;
    margin-right: 20px;
    cursor: pointer;
  }

  .text1 {
    font-family: "苹方-简 中黑体";
    font-size: 16px;
  }

  .text2 {
    font-family: "苹方-简 中黑体";
    font-size: 16px;
    color: #757575;
  }

  .price1 {
    font-size: 30px;
    color: #fff;
  }

  .price1 span {
    font-size: 14px;
    margin: 0px 5px;
    color: #fff;
  }

  .ran1 {
    color: #fff;
  }

  .price2 {
    font-size: 30px;
    color: #000;
  }

  .price2 span {
    font-size: 14px;
    margin: 0px 5px;
    color: #000;
  }

  .ran2 {
    color: #000;
  }

  .pay {
    display: flex;
    flex-direction: row;
    margin-left: 10px;
  }

  div>>>.el-radio__input.is-checked .el-radio__inner {
    border-color: #ff720b;
    background: #ff720b;
  }

  div>>>.el-radio__input.is-checked+.el-radio__label {
    color: #ff720b;
  }

  .input-group-btn:last-child>.btn {
    border-top-left-radius: 8px;
    border-bottom-left-radius: 8px;
  }

  /* 媒体查询 */

  @media (max-width: 992px) {
    .num_box {
      margin-top: 20px;
    }
  }

  @media (max-width: 768px) {}

  @media (max-width: 576px) {}

  @media (max-width: 375px) {

    .panel1,
    .panel2 {
      font-size: 12px;
    }

    .text1,
    .text2 {
      font-size: 14px;
    }

    .num_box {
      margin-top: 20px;
    }
  }

</style>
